import { JJUtil } from "../util/index.js";

class JJShowHelper {

    static toastMessage(title) {
        if (JJUtil.isNull(title) || title.length == 0) {
            return
        }
        // 根据提示信息设置动画时间，最小1s,最大5s
        let durationValue = 5;
        let accurateValue = title.length * 0.06 + 0.5;
        durationValue = (durationValue > accurateValue ? accurateValue : durationValue) * 1000;
        if (durationValue < 1000) {
            durationValue = 1000;
        }
        
        wx.showToast({
            title: title,
            icon: 'none',
            duration: durationValue,
            mask: true
        })
    }

    static showLoading() {
        const systemInfo = wx.getSystemInfoSync()
        const platform = systemInfo.platform
        if (platform == "ios") {
            wx.showLoading({ mask: true })
        } else {
            wx.showLoading({ mask: true, title: '正在加载...' })
        }
    }

    static hideLoading() {
        wx.hideLoading()
    }
}

export default JJShowHelper;
